﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="Stock.aspx.cs" Inherits="UdrinkWater_Project.Officer.Stock" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
      <script type="text/javascript">
    // <![CDATA[
          function ShowSertEmpWindow() {
              pcDataEmp.Show();
          }
          function ShowSertCusWindow() {
              pcCusData.Show();
          }
          function ShowSertProWindow() {
              pcProduct.Show();
          }
    // ]]> 
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <dx:ASPxPopupControl ID="pcProduct" runat="server" CloseAction="CloseButton" Modal="True"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="pcProduct"
        HeaderText="ค้นหาสินค้า" AllowDragging="True" PopupAnimationType="None" EnableViewState="False" Width="960px">
        <ClientSideEvents PopUp="function(s, e) { ASPxClientEdit.ClearGroup('entryGroup'); }" />
         <ContentCollection>
<dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server" SupportsDisabledAttribute="True">
    <table style="width: 100%">
        <tr>
            <td>
                <asp:SqlDataSource ID="SqlProduct" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                    
                    SelectCommand="SELECT TB_Product.Product_ID, TB_Product.Product_name, TB_Unit_Category.Unit_Name, TB_Product.Price, TB_Product.In_Stock, TB_Product.Image_Path FROM TB_Product LEFT JOIN TB_Unit_Category ON TB_Product.Unit = TB_Unit_Category.Unit_ID">
                </asp:SqlDataSource>
            </td>
        </tr>
        <tr>
            <td align="center">
                <dx:ASPxGridView ID="ASPxGridView4" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="SqlProduct" KeyFieldName="Product_ID" Width="80%" 
                    OnRowCommand="ASPxGridView4_RowCommand">
                    <Columns>
                        <dx:GridViewDataTextColumn Caption="เลือก" ShowInCustomizationForm="True" 
                            VisibleIndex="7">
                            <DataItemTemplate>
                                <table style="width: 100%">
                                    <tr>
                                        <td align="center">
                                            <dx:ASPxButton ID="btSertProd" runat="server" Text="เลือก" CommandName="Cmd_Select"  CommandArgument='<%# Eval("Product_ID") %>'>
                                                <ClientSideEvents Click="function(s, e) {
	pcProduct.Hide();
}" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewCommandColumn ShowInCustomizationForm="True" VisibleIndex="0" 
                            Visible="False">
                            <ClearFilterButton Visible="True">
                            </ClearFilterButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataTextColumn FieldName="Product_ID" ReadOnly="True" 
                            ShowInCustomizationForm="True" VisibleIndex="2" Caption="รหัสสินค้า">
                            <Settings AutoFilterCondition="Contains" FilterMode="DisplayText" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Product_name" 
                            ShowInCustomizationForm="True" VisibleIndex="3" Caption="ชื่อสินค้า">
                            <Settings AutoFilterCondition="Contains" FilterMode="DisplayText" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Unit_Name" ShowInCustomizationForm="True" 
                            VisibleIndex="4" Caption="หน่วย">
                            <Settings AutoFilterCondition="Contains" FilterMode="DisplayText" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Price" ShowInCustomizationForm="True" 
                            VisibleIndex="5" Caption="ราคา/หน่วย">
                            <Settings AutoFilterCondition="Contains" FilterMode="DisplayText" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="In_Stock" ShowInCustomizationForm="True" 
                            VisibleIndex="6" Caption="จำนวนคงเหลือ" Visible="False">
                            <Settings AutoFilterCondition="Contains" FilterMode="DisplayText" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataBinaryImageColumn FieldName="Image_Path" 
                            ShowInCustomizationForm="True" VisibleIndex="1" Caption="รูปภาพ" 
                            Visible="False">
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataBinaryImageColumn>
                    </Columns>
                    <Settings ShowFilterRow="True" />
                </dx:ASPxGridView>
            </td>
        </tr>
    </table>
             </dx:PopupControlContentControl>
</ContentCollection>
     </dx:ASPxPopupControl>
     <dx:ASPxPopupControl ID="pcDataEmp" runat="server" CloseAction="CloseButton" Modal="True"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="pcDataEmp"
        HeaderText="ค้นหาพนักงาน" AllowDragging="True" PopupAnimationType="None" 
         EnableViewState="False" Width="960px">
        <ClientSideEvents PopUp="function(s, e) { ASPxClientEdit.ClearGroup('entryGroup'); tbLogin.Focus(); }" />
<ContentCollection>
<dx:PopupControlContentControl ID="PopupControlContentControl2" runat="server" SupportsDisabledAttribute="True">
    <table style="width: 100%">
        <tr>
            <td>
                <asp:SqlDataSource ID="SqlEmp" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                    SelectCommand="SELECT ID_Card,( Prefix + '' + Firstname + ' ' + Lastname ) AS Name FROM TB_Employee">
                </asp:SqlDataSource>
            </td>
        </tr>
        <tr>
            <td align="center">
                <dx:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="SqlEmp" KeyFieldName="ID_Card" Width="80%" 
                    OnRowCommand="ASPxGridView2_RowCommand">
                    <Columns>
                        <dx:GridViewCommandColumn ShowInCustomizationForm="True" Visible="False" 
                            VisibleIndex="0">
                            <ClearFilterButton Text="ยกเลิก" Visible="True">
                            </ClearFilterButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataTextColumn 
                            ShowInCustomizationForm="True" VisibleIndex="3" Caption="เลือก">
                            <DataItemTemplate>
                                <table style="width: 100%">
                                    <tr>
                                        <td align="center">
                                            <dx:ASPxButton ID="btEmpChose" runat="server" Text="เลือก" CommandName="Cmd_Select"  CommandArgument='<%#Eval("ID_Card")%>'>
                                                <ClientSideEvents Click="function(s, e) {
	pcDataEmp.Hide();
}" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                            </DataItemTemplate>
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="ID_Card" ReadOnly="True" 
                            ShowInCustomizationForm="True" VisibleIndex="1" 
                            Caption="ค้นหาจากรหัสพนักงาน" Width="250px">
                            <Settings AutoFilterCondition="Contains" FilterMode="DisplayText" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Name" ReadOnly="True" 
                            ShowInCustomizationForm="True" VisibleIndex="2" Caption="ค้นหาจากชื่อ" 
                            Width="250px">
                            <Settings AutoFilterCondition="Contains" FilterMode="DisplayText" />
                            <HeaderStyle HorizontalAlign="Center" />
                        </dx:GridViewDataTextColumn>
                    </Columns>
                    <Settings ShowFilterRow="True" />
                </dx:ASPxGridView>
            </td>
        </tr>
    </table>
    </dx:PopupControlContentControl>
</ContentCollection>
     </dx:ASPxPopupControl>
      <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" HeaderText="จัดการสินค้าคงคลัง" 
        Width="1080px">
        <HeaderStyle Font-Size="Large" />
        <PanelCollection>
            <dx:PanelContent ID="PanelContent1" runat="server" SupportsDisabledAttribute="True">
                <table style="width: 100%">
                    <tr>
                        <td width="40%" valign="top" style="height: inherit">
                             <asp:Panel ID="Panel2" runat="server">
                                <fieldset><legend>วันที่เวลา</legend>
                                <asp:UpdatePanel ID="updDateOrder" runat="server">
                                    <ContentTemplate>
                                        <table style="width: 100%">
                                            <tr>
                                                <td style="width: 103px">
                                                    <dx:ASPxLabel ID="ASPxLabel3" runat="server" Text="วันเวลาเอกสาร:">
                                                    </dx:ASPxLabel>
                                                </td>
                                                <td>
                                                    <dx:ASPxTextBox ID="txtStockDate" runat="server" Width="225px" ReadOnly="True" 
                                                        BackColor="#D3E4A6">
                                                    </dx:ASPxTextBox>
                                                </td>
                                            </tr>
                                        </table>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </fieldset>
                                 <asp:Panel ID="Panel1" runat="server">
                                     <fieldset>
                                         <legend>พนักงาน</legend>
                                         <asp:UpdatePanel ID="udpEmp" runat="server">
                                             <ContentTemplate>
                                                 <table style="width: 100%">
                                                     <tr>
                                                         <td style="width: 78px">
                                                             <dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="รหัสพนักงาน:">
                                                             </dx:ASPxLabel>
                                                         </td>
                                                         <td style="width: 244px">
                                                             <dx:ASPxTextBox ID="txtEmpID" runat="server" Width="225px" BackColor="#D3E4A6" 
                                                                 ReadOnly="True">
                                                             </dx:ASPxTextBox>
                                                         </td>
                                                         <td style="width: 11px">
                                                             <dx:ASPxButton ID="btEmpSert" runat="server" Text="ค้นหา" Width="60px" 
                                                                 onclick="btEmpSert_Click" AutoPostBack="False" Height="23px">
                                                                 <ClientSideEvents Click="function(s, e) {
	 ShowSertEmpWindow();
}" />
                                                             </dx:ASPxButton>
                                                         </td>
                                                     </tr>
                                                     <tr>
                                                         <td style="width: 78px">
                                                             <dx:ASPxLabel ID="ASPxLabel2" runat="server" Text="ชื่อพนักงาน:">
                                                             </dx:ASPxLabel>
                                                         </td>
                                                         <td style="width: 244px">
                                                             <dx:ASPxTextBox ID="txtEmpName" runat="server" Width="225px" 
                                                                 BackColor="#D3E4A6" ReadOnly="True">
                                                             </dx:ASPxTextBox>
                                                         </td>
                                                         <td>
                                                             &nbsp;</td>
                                                     </tr>
                                                     <tr>
                                                         <td align="center" colspan="3">
                                                             <dx:ASPxLabel ID="lbWarnEmp" runat="server" ForeColor="Red" 
                                                                 Text="ไม่มีพนักงานในระบบ!" Visible="False">
                                                             </dx:ASPxLabel>
                                                         </td>
                                                     </tr>
                                                 </table>
                                             </ContentTemplate>
                                         </asp:UpdatePanel>
                                     </fieldset>
                                     <table style="width: 100%">
                                         <tr>
                                             <td align="center">
                                                 <dx:ASPxButton ID="btSaveAndReport" runat="server" Height="50px" 
                                                     OnClick="btSaveAndReport_Click" Text="บันทึกและพิมพ์ใบเสร็จ" Width="180px">
                                                     <ClientSideEvents Click="function(s, e) {
	alert ('Compleate');
}" />
                                                 </dx:ASPxButton>
                                             </td>
                                         </tr>
                                         <tr>
                                             <td align="center">
                                                 <dx:ASPxButton ID="btNewOrder" runat="server" Height="50px" 
                                                     OnClick="btNewOrder_Click" Text="เริ่มรายการใหม่" Width="180px">
                                                 </dx:ASPxButton>
                                             </td>
                                         </tr>
                                     </table>
                                     </asp:Panel>
                            </asp:Panel>
                        </td>
                        <td width="40%" valign="top" style="height: inherit">
                            <asp:Panel ID="Panel4" runat="server" Height="100%">
                                <fieldset>
                                    <legend>เพิ่มสินค้าในรายการ</legend>
                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                        <ContentTemplate>
                                            <table style="width: 100%">
                                                <tr>
                                                    <td style="width: 127px">
                                                        <dx:ASPxLabel ID="ASPxLabel7" runat="server" Text="รหัสสินค้า:">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                    <td style="width: 360px">
                                                        <dx:ASPxTextBox ID="txtProductId" runat="server" Width="225px" ReadOnly="True" 
                                                            BackColor="#D3E4A6">
                                                        </dx:ASPxTextBox>
                                                    </td>
                                                    <td>
                                                        <dx:ASPxButton ID="btProductSert" runat="server" Text="ค้นหา" Width="60px" 
                                                            AutoPostBack="False" onclick="btProductSert_Click">
                                                            <ClientSideEvents Click="function(s, e) {
	ShowSertProWindow();
}" />
                                                        </dx:ASPxButton>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 127px">
                                                        <dx:ASPxLabel ID="ASPxLabel8" runat="server" Text="ชื่อสินค้า:">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                    <td style="width: 360px">
                                                        <dx:ASPxTextBox ID="txtProductName" runat="server" Width="225px" 
                                                            ReadOnly="True" BackColor="#D3E4A6">
                                                        </dx:ASPxTextBox>
                                                    </td>
                                                    <td>
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 127px">
                                                        <dx:ASPxLabel ID="ASPxLabel10" runat="server" Text="จำนวนคงเหลือ:">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                    <td style="width: 360px">
                                                        <dx:ASPxTextBox ID="txtInStock" runat="server" Width="180px" ReadOnly="True" 
                                                            BackColor="#D3E4A6">
                                                        </dx:ASPxTextBox>
                                                    </td>
                                                    <td rowspan="3">
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 127px">
                                                        <dx:ASPxLabel ID="ASPxLabel12" runat="server" Text="หน่วยสินค้า:">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                    <td style="width: 360px">
                                                        <dx:ASPxTextBox ID="txtUnit" runat="server" Width="180px" ReadOnly="True" 
                                                            BackColor="#D3E4A6">
                                                        </dx:ASPxTextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="height: 23px; width: 127px;">
                                                        <dx:ASPxLabel ID="ASPxLabel9" runat="server" Text="การโอนย้าย:">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                    <td style="height: 23px; width: 360px;">
                                                        <dx:ASPxComboBox ID="cnbCatTarnf" runat="server" Width="180px">
                                                            <Items>
                                                                <dx:ListEditItem Text="เข้าคลัง" Value="เข้าคลัง" />
                                                                <dx:ListEditItem Text="ออกคลัง" Value="ออกคลัง" />
                                                            </Items>
                                                        </dx:ASPxComboBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 127px">
                                                        <dx:ASPxLabel ID="ASPxLabel11" runat="server" Text="จำนวน:">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                    <td style="width: 360px">
                                                        <dx:ASPxTextBox ID="txtCount" runat="server" style="margin-bottom: 0px" 
                                                            Width="180px" ClientInstanceName="txtCount">
                                                        </dx:ASPxTextBox>
                                                    </td>
                                                    <td>
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td align="center" colspan="3">
                                                        <dx:ASPxLabel ID="lbWranNotEnoght" runat="server" ForeColor="Red" 
                                                            Text="จำนวนสินค้าไม่พอทำรายการ!" Visible="False">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="center" colspan="3">
                                                        <dx:ASPxLabel ID="lbWranList" runat="server" ForeColor="Red" 
                                                            Text="สินค้ามีในรายการแล้ว!" Visible="False">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                </tr>
                                            </table>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                               
                                <table style="width: 100%">
                                    <tr>
                                        <td align="center" style="height: 27px">
                                            <dx:ASPxButton ID="btAddList" runat="server" Text="เพิ่มรายการ" 
                                                OnClick="btAddList_Click">
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table> 
                                </fieldset>
                            </asp:Panel>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Panel ID="Panel6" runat="server">
                                <fieldset>
                                    <legend>รายการสินค้า</legend>
                                    <dx:ASPxGridView ID="GV_OrderList" runat="server" Width="100%" 
                                        AutoGenerateColumns="False" Font-Size="Medium" KeyFieldName="Number" 
                                        OnFocusedRowChanged="GV_OrderList_FocusedRowChanged" 
                                        OnRowCommand="GV_OrderList_RowCommand" 
                                        OnSummaryDisplayText="GV_OrderList_SummaryDisplayText">
                                        <TotalSummary>
                                            <dx:ASPxSummaryItem DisplayFormat="รวม {0:#,###.00}" FieldName="TotalRow" 
                                                SummaryType="Sum" />
                                        </TotalSummary>
                                        <Columns>
                                            <dx:GridViewDataTextColumn Caption="รหัสสินค้า" FieldName="Product_ID" 
                                                ShowInCustomizationForm="True" VisibleIndex="1">
                                                <HeaderStyle HorizontalAlign="Center" />
                                                <CellStyle HorizontalAlign="Center">
                                                </CellStyle>
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn Caption="ชื่อสินค้า" FieldName="Product_Name" 
                                                ShowInCustomizationForm="True" VisibleIndex="2">
                                                <HeaderStyle HorizontalAlign="Center" />
                                                <CellStyle HorizontalAlign="Center">
                                                </CellStyle>
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn Caption="หน่วย" FieldName="Unit" 
                                                ShowInCustomizationForm="True" VisibleIndex="3">
                                                <HeaderStyle HorizontalAlign="Center" />
                                                <CellStyle HorizontalAlign="Center">
                                                </CellStyle>
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn Caption="จำนวน" FieldName="Count" 
                                                ShowInCustomizationForm="True" VisibleIndex="5">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn Caption="การโอนย้าย" FieldName="CatTranf" 
                                                ShowInCustomizationForm="True" VisibleIndex="4">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn Caption="รายการ" FieldName="Number" 
                                                ShowInCustomizationForm="True" UnboundType="String" VisibleIndex="0">
                                                <HeaderStyle HorizontalAlign="Center" />
                                                <CellStyle HorizontalAlign="Center">
                                                </CellStyle>
                                                <DataItemTemplate>
                                                    <%#Container.ItemIndex +1 %>
                                                </DataItemTemplate>
                                                <HeaderStyle HorizontalAlign="Center" />
                                                <CellStyle HorizontalAlign="Center">
                                                </CellStyle>
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn Caption="ลบ" ShowInCustomizationForm="True" 
                                                VisibleIndex="8">
                                                <DataItemTemplate>
                                                    <dx:ASPxButton ID="btnImageAndText" runat="server" BackColor="White" 
                                                        CommandArgument="<%# Container.ItemIndex %>" CommandName="Cmd_Delete" 
                                                        Text="ลบรายการ" Width="120px">
                                                        <Image Height="16px" Url="../images/Remove.png" Width="16px">
                                                        </Image>
                                                        <ClientSideEvents Click="function(s,e) { e.processOnServer = confirm('Are you sure?'); }" />
                                                    </dx:ASPxButton>
                                                </DataItemTemplate>
                                                <HeaderStyle HorizontalAlign="Center" />
                                                <CellStyle HorizontalAlign="Center">
                                                </CellStyle>
                                            </dx:GridViewDataTextColumn>
                                        </Columns>
                                        <SettingsBehavior ConfirmDelete="True" />
                                        <Settings ShowFooter="True" ShowGroupFooter="VisibleIfExpanded" />
                                        <SettingsText ConfirmDelete="ยืนยันการลบข้อมูล" />
                                    </dx:ASPxGridView>
                                </fieldset>&nbsp;</asp:Panel>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
                        </td>
                    </tr>
                </table>
            </dx:PanelContent>
        </PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>
